<template>
  <div class="app-container book">
    <div class="content">
      <div class="block" v-for="(item,index) in list" :key="index" @click="goToInfo(item)">
        <div class="item">
          <span class="item-cover" v-if="item.cover" :style="{backgroundImage:'url('+item.cover+')'}"></span>
          <span class="item-cover" v-else style="../../../static/images/base/read.png"></span>
          <div class="item-right">
            <span class="name" v-html="item.mainTitle"></span>
            <span class="author">{{item.author}}</span>
            <span class="desc">{{delHtmlTag(item.content)}}</span>
          </div>
        </div>
      </div>
    </div>
    <div class="pagination">
      <el-pagination :current-page.sync="currentPage" :page-size="10" layout="total, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { geReadList } from "@/api/index";
export default {
  data() {
    return {
      currentPage: 1,
      total:0,
      list: [],
      ReadColumnId:sessionStorage.getItem('ReadColumnId')
    };
  },
  components: {},
  created() {
    this.init();
  },
  watch:{
    $route() {
      this.currentPage = Number(this.$route.query.currentPage) || 1;
      this.init(this.currentPage);
    }
  },
  methods: {
    //详情
    goToInfo(item){
      this.$router.push("/read/content?articleId="+item.articleId)
    },
    //去除里面的标签
    delHtmlTag(str) {
      return str.replace(/<[^>]+>/g, "").replace(/&nbsp;/g, "").replace(/□/g, "");
    },
    init(page, pageSize) {
      geReadList(page, pageSize,this.ReadColumnId)
        .then(res => {
          console.log(res.data);
          this.total = res.data.total;
          this.list = res.data.data;
        })
        .catch(err => {});
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.$router.push(this.$route.path + "?currentPage=" + this.currentPage);
    }
  }
};
</script>
<style lang="less" scoped>
.book {
  padding: 0px 20px 20px 20px;
  border-radius: 10px;
  background: #fff;
  .content {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    margin-bottom: 30px;
    border-bottom: 1px solid #eaeaea;
    .block {
      width: 100%;
      margin-top: 20px;
      padding-bottom: 24px;
      border-bottom: 1px solid #eaeaea;
      margin-bottom: -1px;
      cursor: pointer;
      .item {
        display: flex;
        .item-cover {
          width: 322px;
          height: 160px;
          background: url("/static/images/base/read_box.png") no-repeat;
          background-size: cover;
          border-radius: 10px;
          box-shadow: 0 2px 10px rgba(0,0,0,0.4);
        }
        .item-right {
          flex: 1;
          display: flex;
          flex-direction: column;
          margin-left: 20px;
          .name {
            font-size: 20px;
            margin-top: 10px;
          }
          .author {
            font-size: 18px;
            color: #a1a1a1;
            margin-top: 5px;
          }
          .desc {
            font-size: 16px;
            color: #a1a1a1;
            margin-top: 5px;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 1;
            overflow: hidden;
            height: 20px;
          }
        }
      }
    }
  }
}
</style>


